using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Universum.Model.Domain.Feedbacks;
using Universum.Model.Services.Feedbacks;
using Universum.Infrastructure.Configuration;
using StructureMap;
using Universum.Model.Services.Indexing;

namespace Universum.Controllers
{
	[Authorize]
    public class FeedbackController : UniversumController
    {
		IFeedbackService _FeedbackService { get; set; }
		public FeedbackController (
			System.Security.Principal.IPrincipal principal,
			IFeedbackService feedbackService
			)
			:base(principal)
			{
				_FeedbackService = feedbackService;
			}
        //
        // GET: /Feedback/

        public ActionResult Index()
        {
			ViewData["message"] = "";
			if (ConstantIdentifiers.SPECIAL_USER == CurrentUsername)
			{
				return RedirectToAction<FeedbackController>(it => it.Feedbacks());
			}
            return View();
        }
		[AcceptVerbs(HttpVerbs.Post), ValidateInput(false)]
		public ActionResult Register(Feedback feedback)
		{
			if (feedback.IsNotNull() && feedback.Comment.IsNotNull())
			{
				feedback.ID = Guid.NewGuid();
				feedback.SummitedBy = CurrentUsername;
				_FeedbackService.Register(feedback);
				ViewData["message"] = "Successfully registered comment";
			}
			else
				ViewData["message"] = "Your feedback was not registered";
			return View("Index");
		}
		[Authorize(Users = ConstantIdentifiers.SPECIAL_USER)]
		public ActionResult Feedbacks()
		{
			var model = _FeedbackService.GetAllFeedbacks();
			ViewData.Model = model;
			return View();
		}
		[Authorize(Users = ConstantIdentifiers.SPECIAL_USER), AcceptVerbs( HttpVerbs.Post)]
		public ActionResult RemoveFeedback(Guid id){
			_FeedbackService.RemoveFeedback(id);
			return RedirectToAction<FeedbackController>(
				it => it.Feedbacks());
		}
		

    }
}
